package com.chidopi.market.aa.service.impl;

import java.util.List;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;

import com.chidopi.cdf.dao.IBaseDao;
import com.chidopi.cdf.service.IBaseService;
import com.chidopi.market.aa.domain.FunctionItems;
import com.chidopi.market.aa.domain.Functions;


public class FunctionServiceImpl implements IBaseService<Functions> {
	private static Logger logger = LoggerFactory.getLogger(FunctionServiceImpl.class);

	@Autowired
	@Qualifier("functionDao")
	private IBaseDao<Functions> baseDao;

	@Autowired
	@Qualifier("itemDao")
	private IBaseDao<FunctionItems> functionItemDao;

	public int delete(Functions t) throws Exception {
		return this.baseDao.delete(t);
	}

	public List<Functions> find(String sqlWhere, Object... args) throws Exception {
		logger.debug(sqlWhere);
		return this.baseDao.find(sqlWhere, args);
	}

	public Functions findById(Object id) throws Exception {
		logger.debug("id=" + id);
		Functions function = this.baseDao.findById(id);
		if (null != function) {
			logger.debug("before functionItems");
			List<FunctionItems> functionItems = this.functionItemDao.find("function_id=?", id);
			logger.debug("size=" + functionItems.size());
			function.setFunctionItems(functionItems);
		}
		return function;
	}

	public int insert(Functions t) throws Exception {
		return this.baseDao.insert(t);
	}

	public int update(Functions t) throws Exception {
		return this.baseDao.update(t);
	}

	public int getNextSequence() throws Exception {
		return this.baseDao.getSeqNextValue();
	}

}
